package com.jinlejia.erp.ui.common;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.erp.R;

/**
 * 完成带看（Dialog）
 */

public class FinishDialog extends AlertDialog implements View.OnClickListener {

    public FinishDialog(Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.dialog_finish_visit);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //取消
        TextView cancle = (TextView) window.findViewById(R.id.id_cancel);
        //确定
        TextView confirm = (TextView) window.findViewById(R.id.id_confirm);

        cancle.setOnClickListener(this);
        confirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.id_cancel:
                dismiss();
                break;
            case R.id.id_confirm:
                //确定
                dismiss();
                if (null!=confirmListener){
                    confirmListener.confirm();
                }
                break;
            default:
                break;
        }
    }

    public interface OnConfirmListener {
        public void confirm();
    }

    private OnConfirmListener confirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.confirmListener = listener;
    }
}
